package com.crazydream.wechat.system.service;

import java.io.Serializable;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.crazydream.wechat.common.dao.BaseDAO;
import com.crazydream.wechat.common.utils.QueryParameters;
import com.crazydream.wechat.common.vo.PageVo;
import com.crazydream.wechat.system.model.Role;

@Service("roleService")
public class RoleService {

	@Autowired
	@Qualifier("dao")
	private BaseDAO dao;
	@Transactional
	public List<Role> findByResourceId(Serializable id) {
		return dao.findWithNamedQuery(Role.QUERY_ROLE_BY_RESOURCE,QueryParameters.with("id", id).parameters());
	}
	@Transactional
	public Role findById(Role model) {
		return dao.find(Role.class, model.getId());
	}
	@Transactional
	public PageVo<Role> findForPageList(PageVo<Role> page) {
		return page;
	}
	@Transactional
	public void modify(Role model) {
		dao.update(model);
	}
	@Transactional
	public void removeById(Role model) {
		dao.delete(Role.class,model.getId());
	}
	
	@Transactional
	public void save(Role model) {
		model.setEnabled(1);
		dao.create(model);
	}

}
